
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <time.h>
#include "commtraff.h"

// Mock函数实现 (从原文件保留)
 void MockWpaTraff()
{
    WpaTraff wpa = {0};
    strncpy((char *)wpa.ifName, "wlan0", sizeof(wpa.ifName) - 1);
    wpa.ifName[sizeof(wpa.ifName) - 1] = '\0';
    wpa.signal = 50;
    wpa.noise = 20;
    wpa.snr = 30;
    wpa.txrate = 100;
    wpa.rxrate = 80;
    wpa.realTxrate = 90;
    wpa.realRxrate = 70;
    wpa.txEfficiency = 95;
    wpa.frequency = 2412;
    wpa.txPackets = 1000;
    wpa.rxPackets = 800;
    wpa.chload = 10;
    wpa.txBytes = 102400;
    wpa.rxBytes = 81920;
    wpa.txFailed = 5;
    wpa.txRetries = 10;
    wpa.time = time(NULL);

    CommTraff commTraffWpa = {0};
    commTraffWpa.traffType = WPA_LAYER_DATA;
    commTraffWpa.data.wpaTraff = wpa;
    InsertCommTraff(&commTraffWpa);
}

 void MockHisyseventTraff()
{
    HisyseventData hisysevent = {0};
    strncpy(hisysevent.domain, "COMMTRAFF", sizeof(hisysevent.domain) - 1);
    hisysevent.domain[sizeof(hisysevent.domain) - 1] = '\0';
    strncpy(hisysevent.event, "hisyseventTest", sizeof(hisysevent.event) - 1);
    hisysevent.event[sizeof(hisysevent.event) - 1] = '\0';
    strncpy(hisysevent.field, "PacketCount", sizeof(hisysevent.field) - 1);
    hisysevent.field[sizeof(hisysevent.field) - 1] = '\0';
    // 随机数种子已在主程序中初始化，这里不需要重复初始化
    hisysevent.value = 100 + rand() % 1000;
    hisysevent.time = time(NULL);

    CommTraff commTraffHisysevent = {0};
    commTraffHisysevent.traffType = HISYSEVENT_DATA;
    commTraffHisysevent.data.hisyseventData = hisysevent;
    InsertCommTraff(&commTraffHisysevent);
}

 void MockRpcTraff() {
    RpcTraff rpc = {0};
    rpc.proxyHandle = 1;
    rpc.stubHandle = 2;
    rpc.sendDataLen = 1024;
    rpc.recvDataLen = 512;
    rpc.recvDataSeq = (uint64_t)rand();
    rpc.sendDataSeq = (uint64_t)rand();
    rpc.time = time(NULL);
    rpc.localpid = getpid();
    rpc.localuid = getuid();
    rpc.peerpid = getpid() + 1;
    rpc.peeruid = getuid() + 1;

    CommTraff commTraffRpc = {0};
    commTraffRpc.traffType = RPC_LAYER_DATA;
    commTraffRpc.data.rpcTraff = rpc;
    InsertCommTraff(&commTraffRpc);
}

 void MockSessionTraff() {
    static int session_count = 0;
    SessionTraff session = {0};

    int index = session_count % 10;

    snprintf((char*)session.localSessionName, SESSION_NAME_LEN, "local_%d", index);
    snprintf((char*)session.peerSessionName, SESSION_NAME_LEN, "peer_%d", index);
    snprintf((char*)session.peerUdidHash, COMMTRAFF_UDID_HASH_LEN, "udid_%d", index);

    session.pid = getpid();
    session.time = time(NULL);
    session.handle = rand();
    session.channelId = rand();
    session.connId = rand();
    session.sessionId = rand();
    session.sessionType = index % 3;
    session.sendBytes = 1024 * (index + 1);
    session.recvBytes = 512 * (index + 1);

    CommTraff commTraffSession = {0};
    commTraffSession.traffType = SESSION_LAYER_DATA;
    commTraffSession.data.sessionTraff = session;
    InsertCommTraff(&commTraffSession);

    session_count++;
}

 void MockTransportTraff() {
    static int transport_count = 0;
    TransportTraff transport = {0};

    int index = transport_count % 10;

    snprintf((char*)transport.ifName, sizeof(transport.ifName), "eth%d", index);
    snprintf(transport.local, INET6_ADDRSTRLEN - 1, "192.168.1.%d", index + 1);
    snprintf(transport.remote, INET6_ADDRSTRLEN - 1, "10.0.0.%d", index + 1);

    transport.pid = getpid();
    transport.time = time(NULL);
    transport.protocol = index % 3;
    transport.sockId = index;
    transport.sendBytes = 1024 * (index + 1);
    transport.sendPacks = 10 * (index + 1);
    transport.recvBytes = 512 * (index + 1);
    transport.recvPacks = 5 * (index + 1);

    CommTraff commTraffTransport = {0};
    commTraffTransport.traffType = TRANSPORT_LAYER_DATA;
    commTraffTransport.data.transportTraff = transport;
    InsertCommTraff(&commTraffTransport);

    transport_count++;
}

void MockLinkTraff() {
    LinkTraff link = {0};
    strncpy((char *)link.ifName, "eth0", sizeof(link.ifName) - 1);
    link.ifName[sizeof(link.ifName) - 1] = '\0';
    link.time = time(NULL);
    link.txBytes = 1024;
    link.txPackets = 10;
    link.rxBytes = 512;
    link.rxPackets = 5;
    link.rxErrPackets = rand();
    link.txErrPackets = rand();
    link.rxDropPackets = rand();
    link.txDropPackets = rand();

    CommTraff commTraffLink = {0};
    commTraffLink.traffType = LINK_LAYER_DATA;
    commTraffLink.data.linkTraff = link;
    InsertCommTraff(&commTraffLink);
}

